"""
Redistribution and use in source and binary forms, with or
without modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
  list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
  notice, this list of conditions and the following disclaimer
  in the documentation and/or other materials provided with the distribution.
* Neither the names of the authers, nor the names of its contributors, may be used to endorse or 
  promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE REGENTS/COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND 
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
REGENTS/COPYRIGHT OWNERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

@Author Fredrique Samuels <fredriquesamuels@gmail.com>
@config.py
"""

#=======================================================#

class pytConfigINI:
    """ Class for reading values from a .ini Configuration file"""
    def __init__(self,_file = None):
        """ Class Constructor

        @param _file : File to load"""
        self._data ={}
        if not _file is None:
            self.load(_file)

    def load(self,_file):
        """ Load Config file """
        if not _file.endswith('.ini'):
            raise Exception(_file+" is NOT an .INI file.")

        fh = open(_file)
        data = fh.readlines()
        for d in data:
            _d = d.replace('\n','').split('=')
            self._data[_d[0]] = _d[1]
        

    def getString(self,param):
        """ Get parameter as a string
        
        @param param: parameter name"""
        return str(self._data[param])

    def getInt(self,param):
        """ Get parameter as a Integer
        
        @param param: parameter name"""
        return int(self._data[param])

    def getFloat(self,param):
        """ Get parameter as a Floating
        point number 
        
        @param param: parameter name"""
        return float(self._data[param])

    def getParameterList(self):
        """Get a list of the availible parameters"""
        return self._data.keys()

    def containsParameter(self,param):
        """ Is the given parameter available """
        return self._data.has_key(param)

#=======================================================#

#if __name__ == '__main__':
#    _file = 'test.ini'
#    
#    config = ConfigINI(_file)
#    print config.getInt('TIMEOUT')
#    
